﻿using System;
using System.IO;
using System.Text;

namespace HYCodeBase.LogSuite
{
	public class LogManger
	{
		private LogManger()
		{
			this.AddOneString("创建日志记录");
		}

		public static LogManger GetLogManger(bool ifUseSingeTag = true)
		{
			LogManger logManger;
			if (!ifUseSingeTag)
			{
				logManger = new LogManger();
			}
			else
			{
				if (LogManger.m_singleTag == null)
				{
					LogManger.m_singleTag = new LogManger();
				}
				logManger = LogManger.m_singleTag;
				logManger.AddOneString("获取单例日志记录器");
			}
			return logManger;
		}

		public void Clear()
		{
			this.m_thisStringBuilder.Clear();
			this.m_nThisCount = 0;
		}

		public void AddOneString(string input)
		{
			if (input == null)
			{
				input = string.Empty;
			}
			string text = string.Format("{0} :  {1} : {2}", this.m_nThisCount, DateTime.Now.ToString(), input);
			string text2 = string.Empty;
			for (int i = 0; i < text.Length; i++)
			{
				text2 += "=";
			}
			try
			{
				this.m_thisStringBuilder.AppendLine(text2);
				this.m_thisStringBuilder.AppendLine(text);
				this.m_thisStringBuilder.AppendLine(text2);
			}
			catch (Exception)
			{
			}
			this.m_nThisCount++;
		}

		public bool OutPutLog(string fullPath)
		{
			bool result;
			try
			{
				this.AddOneString("生成报告");
				using (StreamWriter streamWriter = new StreamWriter(fullPath))
				{
					streamWriter.WriteLine(this.m_thisStringBuilder);
				}
				result = true;
			}
			catch (Exception)
			{
				result = false;
			}
			return result;
		}

		private StringBuilder m_thisStringBuilder = new StringBuilder();

		private static LogManger m_singleTag;

		private int m_nThisCount;
	}
}
